#include<func.h>
void cleanup(void *p)
{
    //free(p);
    printf("I am cleanup%ld\n",(long)p);
}

void * sigfunc(void* p)
{//pthread_cleanup_pop(0);平常不执行，只有遇到exit和cancel才执行
    // char* q=(char*)malloc(100);
    // strcpy(q,"hello");
    pthread_cleanup_push(cleanup,(void*)1);
    pthread_cleanup_push(cleanup,(void*)2);
    // printf("malloc success\n");
    sleep(1);
    // printf("start free\n");
    pthread_exit(NULL);
    pthread_cleanup_pop(0);
    pthread_cleanup_pop(0);
    return NULL;
}
int main()
{
    pthread_t pthid;
    char *p;
    int ret=pthread_create(&pthid,NULL,sigfunc,NULL);
    THREAD_ERR_CHECK(ret,"pthread_create")
    ret=pthread_cancel(pthid);
    THREAD_ERR_CHECK(ret,"pthread_cancel")
    ret=pthread_join(pthid,NULL);
    THREAD_ERR_CHECK(ret,"pthread_join");
    printf("I am main thread\n");
    return 0;
}